<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投后会议') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="applyTitle">
        <el-input
          v-model="queryParams.applyTitle"
          :placeholder="$t('申请标题')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('会议类型')" prop="meetingType">
        <el-select v-model="queryParams.meetingType" size="small" filterable clearable :placeholder="$t('会议类型')">
          <el-option
            v-for="dict in meetingTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('会议时间')" prop="meetingTime">
        <DatePicker v-model="dateMeetingTimes" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['bf:postInvestMeet:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfPostInvestMeetList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="applyTitle" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.applyTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议类型')" align="center" prop="meetingType" show-overflow-tooltip min-width="120" :formatter="meetingTypeFormat" />
      <el-table-column :label="$t('会议时间')" align="center" prop="meetingTime" show-overflow-tooltip min-width="120" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.meetingTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('我方参会人员')" align="center" prop="ourParticipants" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('其他参会人员')" align="center" prop="otherParticipants" show-overflow-tooltip min-width="180" />
      <el-table-column fixed="right" :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column fixed="right" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="bf:postInvestMeet" style="display: inline-block;" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投后会议对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <bfPostInvestMeetForm ref="bfPostInvestMeetForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listBfPostInvestMeet, delBfPostInvestMeet } from '@/api/bf/postInvestMeet/bfPostInvestMeet'
import bfPostInvestMeetForm from './bfPostInvestMeetForm.vue'
export default {
    components: {
        bfPostInvestMeetForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 投后会议表格数据
          bfPostInvestMeetList: [],
          // 投后会议类型
          meetingTypeOptions: [],
          dateMeetingTimes: [],
          // 弹出层标题
          title: '投后会议',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              applyTitle: undefined,
              meetingType: undefined,
              meetingTime: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getDicts('post_meeting_type').then(response => {
        this.meetingTypeOptions = response.data
      })
      this.getList()
  },
  methods: {
    /** 查询投后会议列表 */
    getList() {
        this.loading = true
        if (this.dateMeetingTimes != null && this.dateMeetingTimes.length > 1) {
          this.queryParams.startDate = this.dateMeetingTimes[0]
          this.queryParams.endDate = this.dateMeetingTimes[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listBfPostInvestMeet(this.queryParams).then(response => {
            this.bfPostInvestMeetList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    meetingTypeFormat(row) {
      return this.$t(this.selectDictLabel(this.meetingTypeOptions, row.meetingType))
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            applyTitle: undefined,
            meetingType: undefined,
            meetingTime: undefined,
            ourParticipants: undefined,
            otherParticipants: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.dateMeetingTimes = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.bfPostInvestMeetForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.bfPostInvestMeetForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delBfPostInvestMeet(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    }
  }
}
</script>
